﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="IntakeHistory.ascx.cs" Inherits="AntiObesity.Services.IntakeHistory" %>
<span class="history">
    <span class="date-changer" id="dateChanger" runat="server">
        <asp:ImageButton CssClass="inline-button" ID="btnPrev" runat="server" ImageUrl="~/images/prev.png" OnClick="btnPrev_Click" Style="height: 16px" />
        <asp:Label ID="lblDate" runat="server" Text="Today"></asp:Label>
        Intakes
        <asp:ImageButton CssClass="inline-button" ID="btnNext" runat="server" ImageUrl="~/images/next.png" OnClick="btnNext_Click" />
        <asp:TextBox ID="txtDate" CssClass="date-editor" runat="server" Width="100" Text='<%# Date.ToShortDateString() %>'></asp:TextBox>
    </span>
    <asp:GridView CssClass="grid" ID="lstIntakes" runat="server" AutoGenerateColumns="False">
        <Columns>
            <asp:BoundField HeaderText="Food" DataField="Food" />
            <asp:BoundField HeaderText="Amount" DataField="Quantity" />
            <asp:BoundField ReadOnly="true" HeaderText="Total Calories" DataField="TotalCalories" />
            <asp:TemplateField ItemStyle-CssClass="actions" HeaderText="Actions">
                <ItemTemplate>
                    <asp:ImageButton ID="btnDelete" runat="server" CausesValidation="false" ImageUrl="~/images/delete.gif" ToolTip="Delete" CommandArgument='<%# Eval("ID") %>' OnClick="btnDelete_Click" OnClientClick="return confirm('are you sure');" />
                    <asp:ImageButton ID="btnEdit" runat="server" CausesValidation="false" ImageUrl="~/images/edit.gif" ToolTip="Edit" OnClientClick='<%#  String.Format("javascript:changeAmount(\"{0}\",{1});", Eval("ID"), Eval("Quantity")) %>' />
                </ItemTemplate>
                <ItemStyle CssClass="actions" />
            </asp:TemplateField>
        </Columns>
        <EmptyDataTemplate>
            <%# HideEmptyTable ? "" : "No intake in this day." %>
        </EmptyDataTemplate>
        <AlternatingRowStyle CssClass="alt" />
        <HeaderStyle CssClass="header" />
    </asp:GridView>
</span>
<script type="text/javascript">
    $(document).ready(function() {

        $("#<%# txtDate.ClientID %>").datepicker({
            showOn: 'both',
            buttonText: 'Select date',
            buttonImageOnly: true,
            buttonImage: 'images/datePicker.gif',
            onSelect: function(dateText, inst) {
                window.location = "History.aspx" + "?date=" + escape(dateText);
            }
        });

    });

    function changeAmount(id, currentValue) {
        var result = prompt("Please enter a value to change amount", currentValue);
        if (result == null)
            return;
        if (isNaN(parseFloat(result)))
            alert("This is not a valid number");
        else
            CallServer(id + "|" + result);
    }

    function ReceiveServerData(arg) {
        alert(arg);
        window.location = window.location;
    }
</script>
